﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;

using System.Text;
using System.Windows.Forms;
using OpenGado.DATA;
using OpenGado.DATA.Entities;

namespace OpenGado.Win
{
    public partial class frmStorage : Form
    {

        public delegate void UpdateStoreListHandler();

        public UpdateStoreListHandler UpdateStoreList;
        Storage st;

        public frmStorage()
        {
            InitializeComponent();
        }

        public frmStorage(int storeid)
        {
            InitializeComponent();
            st = StorageDataControl.Instance.GetStoreById(storeid);
            txtStorage.Text = st.StoreName;
        }

        private void SaveStore()
        {

            if (st != null)
            {
                st.StoreName = txtStorage.Text;
                StorageDataControl.Instance.Save(st);
            }
            else
            {
                Storage storage = new Storage();
                storage.StoreName = txtStorage.Text;

                StorageDataControl.Instance.Save(storage);
            }
           
        }

        private void btnClose_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void btnSave_Click(object sender, EventArgs e)
        {
            SaveStore();
          
            if (UpdateStoreList != null)
            {
                UpdateStoreList();
            }
            this.Close();
        }


    }
}
